<?php
header("Access-Control-Allow-Origin:*");
require("../lib/init.php");
require("../pojo/token.php");
require("../pojo/role.php");
$token = $_POST['token'];
$id = $_POST['id'];
if (empty($token) or empty($id)) {
    exit("缺少必要参数");
}
if (!checkToken($token)) {
    $code = 400;
    $msg = "没有权限";
} else {
    if (!checkRoleCountById($id)) {
        $code = 400;
        $msg = "该角色下存在多个用户，无法删除";
    } else {
        $sql = "delete from role where id = '$id'";
        if (!MQuery($sql)) {
            $code = 400;
            $msg = "删除失败！";
        } else {
            $code = 200;
            $msg = "删除成功！";
        }
    }
}

echo json_encode(resultmsg($code, $msg));
